package android.slc.appbase.ui.vd.wrapper;

import android.slc.appbase.api.slc.callback.SlcObserver;
import android.slc.box.adapter.LoadMoreDataFormatByFx;
import android.slc.box.adapter.PageModel;
import android.slc.box.or.SlcCallbackConfig;

import java.io.Serializable;

/**
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2022/10/13 上午 10:58
 */
public interface IBaseListPageByFxWrapper<T extends Serializable> extends IBaseListCommonWrapper<PageModel<T>>, OnResultsByFxListener<PageModel<T>> {

    LoadMoreDataFormatByFx<T> getLoadMoreDataFormatByFx();

    void loadMore();

    default SlcObserver<PageModel<T>> createSlcObserver() {
        return createSlcObserver(getLoadMoreDataFormatByFx().getOffset(), SlcCallbackConfig.newBuilder().showToast(false).build());
    }

    default SlcObserver<PageModel<T>> createSlcObserver(int pageIndex) {
        return createSlcObserver(pageIndex, SlcCallbackConfig.newBuilder().showToast(false).build());
    }

    default SlcObserver<PageModel<T>> createSlcObserver(int pageIndex, SlcCallbackConfig slcCallbackConfig) {
        return new SlcObserver<PageModel<T>>(slcCallbackConfig) {
            private final int currentPageIndex = pageIndex;

            @Override
            protected void onSucceed(PageModel<T> data) {
                IBaseListPageByFxWrapper.this.onSucceed(data);
            }

            @Override
            protected void onFailed(int errorCode, String errorMessage) {
                IBaseListPageByFxWrapper.this.onError(currentPageIndex, errorCode, errorMessage);
            }
        };
    }


}
